/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.readystatesoftware.viewbadger.demo.slice;

import com.readystatesoftware.viewbadger.Constants;

import com.readystatesoftware.viewbadger.BadgeView;
import com.readystatesoftware.viewbadger.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.ComponentContainer.LayoutConfig;
import ohos.agp.components.Image;
import ohos.agp.components.PositionLayout;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.app.Context;

/**
 * MainAbilitySlice extends AbilitySlice
 */
public class MainAbilitySlice extends AbilitySlice {
    private Context context;
    private PositionLayout myLayout = new PositionLayout(this);

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        context = getContext();
        LayoutConfig config = new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_CONTENT);
        myLayout.setLayoutConfig(config);
        myLayout.setPadding(Constants.MAGIC_32, Constants.MAGIC_32, Constants.MAGIC_32, Constants.MAGIC_32);

        ShapeElement element = new ShapeElement();
        element.setShape(ShapeElement.RECTANGLE);
        element.setRgbColor(new RgbColor(Constants.MAGIC_204, Constants.MAGIC_204, 0));
        myLayout.setBackground(element);
        Image image = new Image(this);
        image.setPixelMap(ResourceTable.Media_icon);
        myLayout.addComponent(image);
        BadgeView badgeView3 = badgeViewTestCase3("Ok", Color.RED, Constants.MAGIC_30);
        myLayout.addComponent(badgeView3);
        super.setUIContent(myLayout);
    }

    /**
     * TestCase #1 - Set badge view text
     *
     * @param text text
     * @return badgeView BadgeView
     */
    private BadgeView badgeViewTestCase1(String text) {
        BadgeView badgeView = new BadgeView(context);
        badgeView.setText(text);
        badgeView.show();
        return badgeView;
    }

    /**
     * TestCase #2 - Set badge view text & color
     *
     * @param text text
     * @param color Color
     * @return badgeView BadgeView
     */
    private BadgeView badgeViewTestCase2(String text, Color color) {
        BadgeView badgeView = new BadgeView(context);
        badgeView.setText(text);
        badgeView.setTextColor(color);
        badgeView.show();
        return badgeView;
    }

    /**
     * TestCase #3 - Set badge view text, color & text size
     *
     * @param text text
     * @param color Color
     * @param textSize TextSize
     * @return badgeView BadgeView
     */
    private BadgeView badgeViewTestCase3(String text, Color color, int textSize) {
        BadgeView badgeView = new BadgeView(context);
        badgeView.setText(text);
        badgeView.setTextColor(color);
        badgeView.setTextSize(textSize);
        badgeView.show();
        return badgeView;
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
